package com.macro.mall.es.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName:
 * @Description:
 * @Author: zhuwenqiang
 * @Date: 2024/6/5
 */
@Configuration
@RefreshScope
public class InitRestHighLevelClient {

    @Value("${es.hostname}")
    private String hostname;

    @Value("${es.port}")
    private int port;

    @Value("${es.scheme}")
    private String scheme;

    /**
     * 初始化 RestHighLevelClient
     * @return
     */
    @Bean
    public RestHighLevelClient restHighLevelClient() {
        return new RestHighLevelClient(
                RestClient.builder(new HttpHost(hostname, port, scheme)));
    }

}
